﻿/*******************************************************************************
 * author : Kimm King 
 * datetime : 2008年8月19日16:40:54 
 * description :  所有功能的表单form在此组装
 */

extjsbase.forms = {
	ns :'extjsbase.forms',

	create : function(name, config, args) {
		// debugger
		var obj = name; // alert(name);

		if (typeof obj === 'string') {

			obj = eval((obj.indexOf(this.ns) > -1 ? obj : this.ns + '.' + obj) + '()');

		} else if (typeof obj === 'function') {
			obj = obj();
			// } else if (typeof obj === 'object') {
		}
		// extjsbase.el.create('file')

		obj = Ext.apply(obj, config || {}, {
			xtype :'form'
		});
		// debugger
		if (args) {
			if (args.items) { // 额外的items元素
				Ext.each(args.items, function(r) {
					obj.items.push(r);
					// alert(Ext.encode(r));
					}, this);
			}
			if (args.buttons) { // 额外的buttons元素
				Ext.each(args.buttons, function(r) {
					obj.buttons.push(r);
				}, this);
			}
			if (args.record) { // 修改时 添加记录
				// alert(Ext.encode(obj.items[0]));
				Ext.each(obj.items, function(r) {
					r.value = args.record.get(r.name || r.hiddenName);
				}, this);
			}
		}
		;
		if (obj.fileUpload)
			obj.items.push(extjsbase.el.create('file')); // 如果文件上传，加上inputfile

		obj.id = obj.id || obj.name || name;
		// debugger
		return obj;
	},
	
	base : function() {
		return {
			labelWidth :75,
			frame :true,
			bodyStyle :'padding:5px 5px 0',
			width :400,
			defaults : {
				width :230
			},
			defaultType :'textfield',
			items : [],
			buttons : [ {
				text :'提交',
				handler : function(b) {

					var simple = b.ownerCt;

					if (simple.form.isValid()) {
						var versionText = simple.form.el.dom[0].value;
						var uploadText = simple.form.el.dom[1].value;
						if (uploadText.trim() == "") {
							Ext.MessageBox.alert("系统提示", "请选择一个存在的文件路径");
							return;

						}

						var grd = simple.grid.store.data.items;
						for ( var i = 0; i < grd.length; i++) {

							var record = grd[i];

							if (record.get('version') == versionText) {
								Ext.MessageBox.alert("系统提示", "此版本号已经存在");
								return;
							}

						}
						simple.form.doAction('submit', {
							url :simple.url,
							method :'post',
							waitMsg :simple.fileUpload ? '上传中，请稍等...'
									: '提交中，请稍等...',
							// params:'',
							success : function(form, action) {

								simple.grid.getStore().reload();
								Ext.WindowMgr.getActive().close();

								Ext.Msg.alert('系统提示', action.result.message);

							},
							failure : function(form, action) {
								Ext.Msg.alert('系统提示', action.result.message);
							}
						});
					}
				}
			} ]
		}
	},
	
	
	////**************  用户管理    **********
	usermanageLook : function() {

		return {
			labelWidth :75,
			frame :true,
			bodyStyle :'padding:5px 5px 0',
			width :400,
			defaults : {
				width :230
			},
			defaultType :'textfield',
			items : [

			extjsbase.el.create('susername_text', {
				readOnly :true
			}), extjsbase.el.create('spassword_text', {
				readOnly :true
			}), extjsbase.el.create('sdepartmentname_text', {
				readOnly :true
			}), extjsbase.el.create('srankname_text', {
				readOnly :true
			}), extjsbase.el.create('isex_combo', {
				readOnly :true
			}), extjsbase.el.create('sphone_text', {
				readOnly :true
			})

			],
			buttons : [ {
				text :'关闭',
				handler : function() {
					Ext.WindowMgr.getActive().close();
				}
			} ]
		}
	},
	usermanage_base : function() {
		return {
			labelWidth :75,
			frame :true,
			bodyStyle :'padding:5px 5px 0',
			width :400,
			defaults : {
				width :230
			},
			defaultType :'textfield',
			items : [

			extjsbase.el.create('susername_text'),
					extjsbase.el.create('spassword_text'),
					extjsbase.el.create('sdepartmentname_text'),// extjsbase.el.create('roles'),
					extjsbase.el.create('srankname_text'),
					extjsbase.el.create('isex_combo'), extjsbase.el.create('sphone_text') ],

			buttons : [
					{
						text :'提交',
						handler : function(b) {

							var projectPanle = b.ownerCt;

							if (projectPanle.form.isValid()) {
								projectPanle.form
										.doAction(
												'submit',
												{
													url :projectPanle.url,
													method :'post',
													waitMsg :projectPanle.fileUpload ? '上传中，请稍等...'
															: '提交中，请稍等...',
													// params:'',
													success : function(form,
															action) {
														projectPanle.grid
																.getStore()
																.reload();
														Ext.WindowMgr
																.getActive()
																.close();
														Ext.Msg
																.alert(
																		'系统提示',
																		action.result.message);

													},
													failure : function(form,
															action) {
														Ext.Msg
																.alert(
																		'系统提示',
																		action.result.message);
													}
												});
							}
						}
					}, {
						text :'重置',
						handler : function(b) {
							var f = b.ownerCt;
							f.form.reset();
						}
					}, {
						text :'退出',
						handler : function() {
							Ext.WindowMgr.getActive().close();
						}
					} ]
		};
	},
	usermanage_search : function() {

		return {
			labelWidth :75,
			frame :true,
			bodyStyle :'padding:5px 5px 0',
			width :400,
			defaults : {
				width :230
			},
			defaultType :'textfield',
			items : [ extjsbase.el.create('user_search_text') ],
			buttons : [
					{
						text :'提交',
						handler : function(b) {
							var projectPanle = b.ownerCt;

							projectPanle.grid.getStore().baseParams.search = Ext
									.getCmp("user_search_text").getValue();
							projectPanle.grid.getStore().reload();
							Ext.WindowMgr.getActive().close();
						}
					}, {
						text :'重置',
						handler : function(b) {
							var f = b.ownerCt;
							f.form.reset();
						}
					}, {
						text :'退出',
						handler : function() {
							Ext.WindowMgr.getActive().close();
						}
					} ]
		};
	}
}